home *** CD-ROM | disk | FTP | other *** search
- /* Copyright (c) 2008 Pearl Crescent, LLC. All Rights Reserved. */
- /* vim: set sw=2 sts=2 ts=8 et syntax=javascript: */
-
- function AviaryProgressMeter()
- {
- this.init();
- }
-
- AviaryProgressMeter.prototype =
- {
- mPearlUtil: null,
- mProgressBox: null,
- mName: null,
- mCancelCallback: null,
- mIsCanceling: false,
-
- init: function()
- {
- this.mPearlUtil = com.aviary.talon.pearlutil;
-
- var vbox = document.createElement("vbox");
- var label = document.createElement("label");
- var hbox = document.createElement("hbox");
- var progressmeter = document.createElement("progressmeter");
- var btn = document.createElement("toolbarbutton");
-
- if (vbox && label && hbox && progressmeter && btn)
- {
- const kClassName = "aviary-progressbox";
- vbox.setAttribute("pack", "center");
- vbox.setAttribute("class", kClassName);
- label.setAttribute("crop", "end");
- label.setAttribute("class", "aviary-progresslabel");
- progressmeter.setAttribute("value", "0");
- progressmeter.setAttribute("mode", "undetermined");
-
- var self = this;
- btn.addEventListener("command", function() { self.Cancel(); }, false);
- var tt = this.mPearlUtil.GetLocalizedString("CANCEL_TOOLTIP");
- btn.setAttribute("tooltiptext", tt);
- btn.setAttribute("hidden", "true");
- btn.setAttribute("class", "toolbarbutton-1 aviary-cancelprogress");
-
- hbox.setAttribute("align", "center");
-
- hbox.appendChild(progressmeter);
- hbox.appendChild(btn);
- vbox.appendChild(label);
- vbox.appendChild(hbox);
-
- // Insert to the right of the Aviary Capture button or, if not found,
- // to the end of the Navigation toolbar.
- var insertBeforeNode;
- var captureBtn = document.getElementById("aviary-captureimageofpage");
- if (captureBtn)
- {
- insertBeforeNode = captureBtn.nextSibling;
- while (insertBeforeNode
- && "vbox" == insertBeforeNode.localName
- && kClassName == insertBeforeNode.getAttribute("class"))
- {
- // Skip past other progress meters.
- insertBeforeNode = insertBeforeNode.nextSibling;
- }
- }
-
- if (insertBeforeNode)
- insertBeforeNode.parentNode.insertBefore(vbox, insertBeforeNode);
- else
- {
- var navToolbar = document.getElementById("nav-bar");
- if (navToolbar)
- navToolbar.appendChild(vbox);
- }
-
- if (vbox.parentNode) // Did we add it?
- {
- this.mProgressBox = vbox;
- this.SetIsCancelable(false);
- }
- }
- },
-
- Cancel: function()
- {
- if (!this.mIsCancelable)
- return;
-
- var str = this.mPearlUtil.GetLocalizedString("CANCELING");
- this.SetLabel(str);
- this.mIsCanceling = true;
-
- if (this.mCancelCallback)
- this.mCancelCallback();
- },
-
- IsCanceled: function()
- {
- return this.mIsCanceling;
- },
-
- SetCancelFunction: function(aFunc)
- {
- this.mCancelCallback = aFunc;
- },
-
- SetIsCancelable: function(aIsCancelable)
- {
- this.mIsCancelable = aIsCancelable;
-
- try
- {
- var cancelBtn = this.mProgressBox.firstChild.nextSibling
- .firstChild.nextSibling;
- if (aIsCancelable)
- cancelBtn.removeAttribute("hidden");
- else
- cancelBtn.setAttribute("hidden", true);
- }
- catch(e) {}
- },
-
- SetName: function(aName)
- {
- if (!aName)
- aName = "";
-
- this.mName = aName;
-
- if (this.mProgressBox)
- this.mProgressBox.setAttribute("tooltiptext", aName);
- },
-
- SetLabel: function(aLabel)
- {
- if (!this.mIsCanceling && this.mProgressBox && this.mProgressBox.firstChild)
- {
- if (!aLabel)
- aLabel = "";
- this.mProgressBox.firstChild.setAttribute("value", aLabel);
- }
- },
-
- SetValue: function(aValue)
- {
- if (this.mProgressBox && this.mProgressBox.firstChild)
- {
- var parent = this.mProgressBox.firstChild.nextSibling;
- var meter = (parent) ? parent.firstChild : null;
- if (meter)
- {
- if (meter.mode == "undetermined")
- meter.mode = "determined";
- meter.setAttribute("value", aValue);
- }
- }
- },
-
- Close: function(aDoFade, aStringName)
- {
- if (this.mProgressBox)
- {
- if (aDoFade)
- {
- var name = (this.mName) ? this.mName : "";
- var str = name;
- if (aStringName)
- {
- str = this.mPearlUtil
- .GetFormattedLocalizedString(aStringName, [name], 1);
- }
-
- this.SetLabel(str);
-
- var fader = new AviaryElementFader(this.mProgressBox);
- }
- else
- this.mProgressBox.parentNode.removeChild(this.mProgressBox);
- }
- },
-
- endOfObject: true
- }
-
-
- function AviaryElementFader(aElem)
- {
- this.init(aElem);
- }
-
- AviaryElementFader.prototype =
- {
- kInitialDelayMS: 5000, // Wait 5 seconds before starting the fade.
- kFadeTimeMS: 3000, // 3 seconds of fading.
- kFadeIncrement: 0.05, // Change the opacity this much each time.
-
- mElem: null,
- mStepDelay: 0,
-
- init: function(aElem)
- {
- if (!aElem)
- return;
-
- this.mStepDelay = Math.floor(this.kFadeTimeMS * this.kFadeIncrement);
-
- this.mElem = aElem;
- this.mElem.style.opacity = 1.0;
- var self = this;
- window.setTimeout(function() {self.fadeStep()}, this.kInitialDelayMS, self);
- },
-
- fadeStep: function()
- {
- var opacity = parseFloat(this.mElem.style.opacity);
- if (opacity > 0)
- {
- opacity -= this.kFadeIncrement;
- this.mElem.style.opacity = opacity;
- var self = this;
- window.setTimeout(function() {self.fadeStep()}, this.mStepDelay, self);
- }
- else
- {
- this.mElem.parentNode.removeChild(this.mElem);
- }
- },
-
- endOfObject: true
- }
-